﻿namespace Raffles.OA.Utility
{
    public class DataResult
    {
        public bool success { get; set; }
        public string message { get; set; }
        public DataResult() { } 
        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static DataResult Success(string message = "操作成功")
        {
            return new DataResult() { success = true, message = message };
        }
        /// <summary>
        /// 错误返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static DataResult Error(string message = "操作失败")
        {
            return new DataResult() { success = false, message = message };
        } 
    }
    public class DataResult<T> : DataResult
    {
        /// <summary>
        /// 列表的记录数
        /// </summary>
        public int total { get; set; }
        /// <summary>
        /// 数据
        /// </summary>
        public T data { get; set; }
        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static DataResult<T> Success(T data, string message = "操作成功")
        {
            return new DataResult<T>() { success = true, message = message, data = data };
        }
        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static DataResult<T> PageResult(T data,int total, string message = "操作成功")
        {
            return new DataResult<T>() { success = true, message = message, data = data, total= total };
        }
        /// <summary>
        /// 警告返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static DataResult<T> Warn(T data, string message = "操作警告")
        {
            return new DataResult<T>() { success = true, message = message, data = data };
        }
        /// <summary>
        /// 错误返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static DataResult<T> Error(T data, string message = "操作失败")
        {
            return new DataResult<T>() { success = false, message = message, data = data };
        }
    }
}
